package huawei.js2025;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 构成指定长度字符串的个数
 */
public class Question36 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> collect = Arrays.stream(sc.nextLine().split(" ")).map(String::trim).collect(Collectors.toList());
        String str = collect.get(0);
        int len = Integer.parseInt(collect.get(1));

        Set<Integer> used = new HashSet<>();

        Set<String> complete = new HashSet<>();

        StringBuilder sb = new StringBuilder();
        find(str, used, len, sb, complete);
        System.out.println(complete);
        System.out.println(complete.size());
    }

    public static void find(String str, Set<Integer> used, int len,StringBuilder sb, Set<String> complete) {
        if (sb.length() == len) {
            complete.add(sb.toString());
            return;
        }

        for (int i = 0; i < str.length(); i++) {
            if (!used.contains(i) && (sb.length() == 0 || str.charAt(i) != sb.charAt(sb.length()-1))) {
                sb.append(str.charAt(i));
                used.add(i);
                find(str, used, len, sb, complete);
                used.remove(i);
                sb.deleteCharAt(sb.length()-1);
            }
        }

    }
}
